package org.shoukaiseki.aqoeous.model;

import com.alibaba.fastjson.JSONObject;
import org.shoukaiseki.aqoeous.handler.AqoeousTriggerHandler;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  18-12-4 下午2:37<br>
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
public class CustomQO {


    /**
     * 返回map中的key名称,如果为空,则设置为qoName名称
     */
    private String resultName;

    /**
     * qo名称
     */
    @NotNull
    private String qoName;

    /**
     * 将数据合并到父级,该qo在子级时才生效,合并到父级使用的字段名为 resultName
     *
     * 子级无关联查询时才能使用
     *
     * 不能设置为默认 true,因为主查询可以不合并到父级
     */
    private boolean mergeParent=false;

    /**
     * 将子表的total总数合并到父级对象中,查询时的pageSize推荐使用-1,或者0
     * <br>
     * mergeParent 为 true 时生效,优先级高于 listFirstMergeParent 和 listMergeParent
     * <br>
     * 将 total 记录合并到父级,该qo在子级时才生效,合并到父级使用的字段名为 resultName
     */
    private boolean pageTotalMergeParent=false;

    /**
     * mergeParent 为 true 时生效,适合无分页
     * <br>
     * 将首条记录合并到父级,该qo在子级时才生效,合并到父级使用的字段名为 resultName
     */
    private boolean listFirstMergeParent=false;

    /**
     * mergeParent 为 true 时生效,适合无分页
     * <br>
     *  listFirstMergeParent 启用后该功能失效
     *
     */
    private boolean listMergeParent=false;



    /**
     * qoJson数据,查询的参数值
     */
    @NotNull
    private JSONObject qoJson=new JSONObject();

    /**
     * 关联关系
     */
//    @JSONField(deserializeUsing = RelationshipQO.class)
    private List<RelationshipQO> relationships;

    /**
     * 子级
     */
//    private List<CustomQO> customQO;

//    @JSONField(deserializeUsing = CustomQODeserializer.class)
    private List<CustomQO> qoChilds;


    //仅仅显示包含的字段,如果该字段设置了值, excludeFieldList 将失效
    private List<String>   includeFieldList;

    //返回值 排除一些字段
    //先进行包含设置,再进行排除
    private List<String>   excludeFieldList;

    //触发器 bean 名称,用于处理查询前,查询后数据处理,调用 spring 中的bean
    private String triggerBean;

    //如果 该字段有值,则 triggerBean失效
    private AqoeousTriggerHandler triggerHandler;

    public CustomQO() {
    }


    public String getQoName() {
        return qoName;
    }

    public void setQoName(String qoName) {
        if(this.resultName==null){
            this.resultName=qoName;
        }
        this.qoName = qoName;
    }

    public boolean isMergeParent() {
        return mergeParent;
    }

    public void setMergeParent(boolean mergeParent) {
        this.mergeParent = mergeParent;
    }

    public boolean isListFirstMergeParent() {
        return listFirstMergeParent;
    }

    public void setListFirstMergeParent(boolean listFirstMergeParent) {
        this.listFirstMergeParent = listFirstMergeParent;
    }

    public boolean isListMergeParent() {
        return listMergeParent;
    }

    public void setListMergeParent(boolean listMergeParent) {
        this.listMergeParent = listMergeParent;
    }

    public JSONObject getQoJson() {
        return qoJson;
    }

    public void setQoJson(JSONObject qoJson) {
        this.qoJson = qoJson;
    }

    public List<RelationshipQO> getRelationships() {
        return relationships;
    }

    public void setRelationships(List<RelationshipQO> relationships) {
        this.relationships = relationships;
    }

    public String getResultName() {
        return resultName;
    }

    public void setResultName(String resultName) {
        this.resultName = resultName;
    }

    public List<CustomQO> getQoChilds() {
        return qoChilds;
    }

    public void setQoChilds(List<CustomQO> qoChilds) {
        this.qoChilds = qoChilds;
    }

    public List<String> getExcludeFieldList() {
        return excludeFieldList;
    }

    public void setExcludeFieldList(List<String> excludeFieldList) {
        this.excludeFieldList = excludeFieldList;
    }

    public List<String> getIncludeFieldList() {
        return includeFieldList;
    }

    public void setIncludeFieldList(List<String> includeFieldList) {
        this.includeFieldList = includeFieldList;
    }

    public boolean isPageTotalMergeParent() {
        return pageTotalMergeParent;
    }

    public void setPageTotalMergeParent(boolean pageTotalMergeParent) {
        this.pageTotalMergeParent = pageTotalMergeParent;
    }

    public String getTriggerBean() {
        return triggerBean;
    }

    public void setTriggerBean(String triggerBean) {
        this.triggerBean = triggerBean;
    }

    public AqoeousTriggerHandler getTriggerHandler() {
        return triggerHandler;
    }

    public void setTriggerHandler(AqoeousTriggerHandler triggerHandler) {
        this.triggerHandler = triggerHandler;
    }
}

